import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';

export const columns: BasicColumn[] = [
  {
    title: '用户姓名',
    dataIndex: 'userName',
    width: 120,
  },
  {
    title: '证件类型',
    dataIndex: 'identityType',
    width: 120,
    customRender: ({ record }: Recordable) => {
      const identityTypeArray = [
        { label: '身份证', value: 1 },
        { label: '护照', value: 2 },
        { label: '港澳通行证', value: 3 },
        { label: '台胞证', value: 4 },
        { label: '其他', value: 5 },
      ];
      const identityType: any = identityTypeArray.find((item) => item.value == record.identityType);
      if (identityType) {
        return identityType.label;
      }
      return '';
    },
  },
  {
    title: '证件号码',
    dataIndex: 'identityNo',
    width: 170,
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 120,
  },
  {
    title: '紧急电话',
    dataIndex: 'telePhone',
    width: 120,
  },
  {
    title: '国籍',
    dataIndex: 'nationality',
    width: 120,
  },
  {
    title: '签发地',
    dataIndex: 'issueAt',
    width: 120,
  },
  {
    title: '有效期',
    dataIndex: 'expiryDate',
    width: 120,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 120,
  },
  {
    title: '性别',
    dataIndex: 'sex',
    width: 120,
  },
  {
    title: '会员年龄',
    dataIndex: 'age',
    width: 120,
  },
  {
    title: '出生日期',
    dataIndex: 'birthDate',
    width: 120,
  },
  {
    title: '英文名',
    dataIndex: 'firstName',
    width: 120,
  },
  {
    title: '英文姓',
    dataIndex: 'lastName',
    width: 120,
  },
  {
    title: '是否本人',
    dataIndex: 'isOneself',
    width: 120,
    customRender: ({ record }: Recordable) => {
      const isOneselfArray = [
        { label: '是', value: 1 },
        { label: '否', value: 2 },
      ];
      const isOneself: any = isOneselfArray.find((item) => item.value == record.isOneself);
      if (isOneself) {
        return isOneself.label;
      }
      return '';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [];

export const formSchema: FormSchema[] = [
  {
    label: '主键',
    field: 'privateDataId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '用户id',
    field: 'userId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '类型',
    field: 'dataType',
    component: 'Input',
    defaultValue: 2,
    required: true,
    show: false,
  },
  {
    label: '用户姓名',
    field: 'userName',
    component: 'Input',
    required: true,
  },
  {
    label: '英文姓',
    field: 'lastName',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    label: '英文名',
    field: 'firstName',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    label: '手机号',
    field: 'mobile',
    component: 'Input',
    required: true,
  },
  {
    label: '证件类型',
    field: 'identityType',
    component: 'Select',
    defaultValue: 1,
    required: true,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '身份证', value: 1 },
          { label: '护照', value: 2 },
          { label: '港澳通行证', value: 3 },
          { label: '台胞证', value: 4 },
          { label: '其他', value: 5 },
        ],
        onChange: (identityType) => {
          console.info('identityType', identityType);
          if (identityType == 1) {
            formModel.lastName = null;
            formModel.firstName = null;
            formModel.nationality = null;
            formModel.sex = null;
            formModel.birthDate = null;
            formModel.issueAt = null;
            formModel.expiryDate = null;
          }
        },
      };
    },
  },
  {
    label: '证件号码',
    field: 'identityNo',
    component: 'Input',
    required: true,
  },
  {
    label: '紧急电话',
    field: 'telePhone',
    component: 'Input',
    required: true,
  },
  {
    label: '出生日期',
    field: 'birthDate',
    component: 'DatePicker',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    label: '性别',
    field: 'sex',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '女', value: 1 },
        { label: '男', value: 2 },
      ],
    },
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    label: '会员年龄',
    field: 'age',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    label: '国籍',
    field: 'nationality',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    label: '签发地',
    field: 'issueAt',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    label: '有效期',
    field: 'expiryDate',
    component: 'DatePicker',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    label: '是否本人',
    field: 'isOneself',
    component: 'RadioButtonGroup',
    required: true,
    defaultValue: 2,
    componentProps: {
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 2 },
      ],
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
];
